using System.Runtime.Serialization;
using SqlSugar;
using Vin.Extension.Framework.Attributes;
using Vin.Extension.Framework.Entities;
using Vin.Extension.SqlSugar.Attributes;

namespace Vin.Extension.Framework.Quartz.Entities;

[Description("StatusText")]
public enum JobRecordStatus
{
    /// <summary>
    /// 运行
    /// </summary>
    [EnumMember(Value = "运行中")] Running = 1,

    /// <summary>
    /// 成功
    /// </summary>
    [EnumMember(Value = "执行完成")] Success = 10,

    /// <summary>
    /// 失败
    /// </summary>
    [EnumMember(Value = "执行异常")] Faild = 20,
}

/// <summary>
/// 任务记录
/// </summary>
[VinSqlSugarEntity("任务记录")]
public record SysJobRecord : VinFrameworkBaseRecordEntity
{
    /// <summary>
    /// 任务id
    /// </summary>
    [SugarColumn(ColumnDescription = "任务id")]
    public long? JobId { get; set; }

    /// <summary>
    /// 任务名称
    /// </summary>
    [SugarColumn(ColumnDescription = "任务名称")]
    public string? JobName { get; set; }

    /// <summary>
    /// 任务分组
    /// </summary>
    [SugarColumn(ColumnDescription = "任务分组")]
    public long? GroupId { get; set; }

    /// <summary>
    /// 执行时间
    /// </summary>
    [SugarColumn(ColumnDescription = "执行时间", DefaultValue = "now()")]
    public DateTime? ExecuteTime { get; set; }

    /// <summary>
    /// 消耗时间
    /// </summary>
    [SugarColumn(ColumnDescription = "消耗时间", DefaultValue = "0")]
    public long? CostTime { get; set; }

    /// <summary>
    /// 总循环次数
    /// </summary>
    [SugarColumn(ColumnDescription = "总循环次数")]
    public int? LoopCount { get; set; }

    /// <summary>
    /// 当前循环次数
    /// </summary>
    [SugarColumn(ColumnDescription = "当前循环次数")]
    public int? CurrentLoopCount { get; set; }

    /// <summary>
    /// 程序集路径
    /// </summary>
    [SugarColumn(ColumnDescription = "程序集路径", DefaultValue = "''")]
    public string? AssemblyPath { get; set; }

    /// <summary>
    /// 执行的程序集名称
    /// </summary>
    [SugarColumn(ColumnDescription = "执行的程序集名称", DefaultValue = "''")]
    public string? AssemblyName { get; set; }

    /// <summary>
    /// 执行的任务类名
    /// </summary>
    [SugarColumn(ColumnDescription = "执行的任务类名")]
    public string? ClassName { get; set; }

    /// <summary>
    /// 任务参数
    /// </summary>
    [SugarColumn(ColumnDescription = "任务参数", IsJson = true, ColumnDataType = "json")]
    public List<JobParams>? Parameters { get; set; }

    /// <summary>
    /// 状态 0:运行 10:成功 20:失败
    /// </summary>
    [SugarColumn(ColumnDescription = "状态 0:运行 10:成功 20:失败", DefaultValue = "0")]
    public JobRecordStatus? Status { get; set; }

    /// <summary>
    /// 异常信息
    /// </summary>
    [SugarColumn(ColumnDescription = "异常信息", ColumnDataType = "text")]
    public string? Exception { get; set; }
}